<?php
    header('Access-Control-Allow-Origin: *');
    header('Content-Type:application/json;charset=utf-8');
    $con = mysqli_connect("127.0.0.1", "root", "root", "mydb");
    $classId = $_GET['classId'];
    $uId = $_GET['uid'];
    $status = $_GET['status'];
    $signInfo = array();
    $classInfo = array();
    $stuList = array();
    if($status == 'student'){
        $sql = "SELECT s.stu_name,le.create_at FROM stu_info as s INNER JOIN lesson_sign as le on s.stu_id = le.s_id WHERE l_id = '$classId' AND s.stu_id = '$uId' ORDER BY le.create_at asc;";
        $res = mysqli_query($con,$sql);
        while($row = mysqli_fetch_array($res)){
            $item = array(
                'stu_name' => $row['stu_name'],
                'create_at' => $row['create_at'],
            );
            array_push($signInfo,$item);
        }
    }else if($status == 'teacher'){
        $sql = "SELECT * FROM lessonstu AS l INNER JOIN stu_info AS s ON l.s_id = s.stu_id WHERE l.l_id = '$classId' and l.state = 'success';";
        $res = mysqli_query($con,$sql);
        while($row = mysqli_fetch_array($res)){
            $item = array(
                'stuId' => $row['stu_id'],
                'stuName' => $row['stu_name'],
            );
            array_push($stuList,$item);
        }
    }
    $sql1 = "SELECT * from lesson as l inner join tch_info as t on l.teacher_id = t.t_id where l_id = '$classId';";
    $res1 = mysqli_query($con,$sql1);
    while($row = mysqli_fetch_array($res1)){
        $classInfo = array(
            'l_id' => $row['l_id'],
            'l_name' => $row['l_name'],
            't_name' => $row['t_name'],
            'l_time' => $row['l_time'],
            'l_place' => $row['l_place'],
            'isSign' => $row['isSign'],
            'signPwd' => $row['signPwd']
        );
        // array_push($classInfo,$item1);
    }
    echo json_encode(array(
        'classInfo'=>$classInfo,
        'stuList'=>$stuList,
        'signInfo'=>$signInfo
    ));
    mysqli_close($con);
?>